/***************************************************************************
 *   Copyright (C) 2008 by Tomasz Dubik                                    *
 *   tdubik@gmail.com                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "shortcuts.h"
#include "actioncollection.h"
#include "common.h"
#include "settings.h"
#include <QAction>
#include <QKeySequence>

void Shortcuts::addShortcut(QAction* _pAction, const QString & _actionName, const QString & _shortcut ) {
    qDebug() << Q_FUNC_INFO << "with:" << _pAction << " name:" << _actionName << " shortcut: " << _shortcut ;
    QString shrt ; 
    if ( _shortcut.isEmpty() )
    {
        shrt = "shortcut/" + _actionName ; 
        shrt = Settings::value( shrt ).toString() ;
        if ( shrt.isEmpty() ) 
        {
            shrt = getDefault( _actionName );
            if ( shrt.isEmpty() )
            {
                qDebug() << "Unable to get default shortcut for action ;( " ; 
                return ; 
            }
        }
    }
    else
        shrt = _shortcut;
    _pAction->setShortcut( QKeySequence( shrt ) );
}
QString Shortcuts::getDefault(const QString& _actionName) {
    if ( _actionName == "add" )
        return "Ctrl+A";
    else if ( _actionName == "quit" )
        return "Ctrl+Q";
    else if ( _actionName == "hide" )
        return "Ctrl+H";
    else if ( _actionName == "restore" )
        return "Ctrl+R";
    return "";
}
void Shortcuts::saveShortcut(const QString& _actionName, const QString& _shrt) {
    QString key ; 
    key = "shortcut/" + _actionName ; 
    Settings::setValue(key, _shrt);
}
